package com.example.demo.controller;

import com.example.demo.pojo.Employee;
import com.example.demo.pojo.EmployeeDo;
import com.example.demo.pojo.Result;
import com.example.demo.service.DeptService;
import com.example.demo.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 *
 * @Description: EmpController
 * </p>
 * @Author yangjiwang
 * @Date 2023/2/27
 */
@RestController
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    private EmpService empService;

    @Autowired
    private DeptService deptService;

    @PostMapping("/create")
    private Result<Employee> createEmp(@RequestBody EmployeeDo emp) {
        return empService.createOrUpdate(emp);
    }

    @GetMapping("/list")
    private Result<List<EmployeeDo>> listEmpByDept(@RequestParam("deptName") String deptName) {
        return empService.listEmpByDept(deptName);
    }

    @PostMapping("/import")
    public Result<Employee> importEmpByExcel(@RequestBody(required = false) MultipartFile file) {
        return empService.parseExcel(file);
    }

}
